﻿create procedure [mem].[kvTouch]
(
	@Key varchar(255) not null,
	@TTL float not null,
	@Version int out,
	@Expiry datetime2 out
) 
with NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER
as
begin atomic with (TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english')

	set @Expiry = dateadd(millisecond, @TTL, getutcdate());
	update mem.kv
	set
		Expiry = @Expiry, 
		@Version = [Version]
	where [Key] = @Key

	if @@rowcount = 0
	begin
		set @Version = -2147483647
		return;
	end
end